package com.apes.fa.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = FaInventoryLossCard.CONST_TABLE_NAME)
public class FaInventoryLossCard extends Model {

    public static final String CONST_TABLE_NAME = "fa_inventory_loss_card";

    @Id
    @Column(name = "id", nullable = false, length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "资产盘亏的卡片(盘点处理表明细)")
    @Comment("编号")
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "fa_card_id", referencedColumnName = "id")
    @Comment("资产卡片")
    private FaCard faCard;

    @Column(name = "product_id")
    @Comment("商品编号")
    private String productId;

    @Column(name = "product_name")
    @Comment("商品名称")
    private String productName;

    @Column(name = "asset_whereabouts")
    @Comment("资产去向")
    private String assetWhereabouts;

    @Column(name = "inventory_loss_reason")
    @Comment("盘亏原因")
    private String inventoryLossReason;

    @Column(name = "use_department_opinion")
    @Comment("使用部门意见")
    private String useDepartmentOpinion;

    @Column(name = "approve_department_opinion")
    @Comment("审批部门意见")
    private String approveDepartmentOpinion;

    @Column(name = "loss_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("盘亏金额")
    private double lossAmount = 0;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "fa_inventory_process_table_id", referencedColumnName = "id", nullable = false)
    @Comment("资产盘点处理表")
    private FaInventoryProcessTable faInventoryProcessTable;

    @Transient
    private String mid;
    public String getMid() {
        if(this.faInventoryProcessTable.getId() != null) return this.faInventoryProcessTable.getId();
        return null;
    }

    @Transient
    private String resolvePerson;

    public String getResolvePerson(){
        if(this.faInventoryProcessTable.getApproveUid() != null) return this.faInventoryProcessTable.getApproveUid().getName();
        return null;
    }

    @Transient
    private String resolveDate;

    public String getResolveDate(){
        if(this.faInventoryProcessTable.getApproveDate() != null) return this.faInventoryProcessTable.getApproveDate().toString();
        return null;
    }

    @Transient
    private String inventoryId;

    public String getInventoryId(){
        if(this.faInventoryProcessTable.getInventoryId() != null) return this.faInventoryProcessTable.getInventoryId();
        return null;
    }

    //卡片编码 展示用
    @Transient
    private String faCardId;

    public String getFaCardId() {
        return this.faCard.getId();
    }



}
